﻿using System; 
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Matrix.Common.DBUtility;
using Matrix.MaKaYunShang.Model;

namespace Matrix.MaKaYunShang.DAL
{
	public partial class ShopSubsidiaryInfoDAL : BaseDAL<ShopSubsidiaryInfoDAL>
	{
        #region 默认方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ShopSubsidiaryInfo model)
        {
            var strSql = new StringBuilder();
            strSql.Append("insert into ShopSubsidiaryInfo(");
            strSql.Append("ShopId,AccountMoney,TotalPayMoney,TotaChargeMoney,PlatformTotalPayMoney,ShopTotalPayMoney,AddTime,UpdateTime,TotalCanSendCard,AlreadySendCard,IsDelete");
            strSql.Append(") values (");
            strSql.Append("@ShopId,@AccountMoney,@TotalPayMoney,@TotaChargeMoney,@PlatformTotalPayMoney,@ShopTotalPayMoney,@AddTime,@UpdateTime,@TotalCanSendCard,@AlreadySendCard,@IsDelete");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
			            new SqlParameter("@ShopId", SqlDbType.Int,4) ,            
                        new SqlParameter("@AccountMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@TotalPayMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@TotaChargeMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@PlatformTotalPayMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ShopTotalPayMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@AddTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@TotalCanSendCard", SqlDbType.Int,4) ,            
                        new SqlParameter("@AlreadySendCard", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1)             
              
            };

            parameters[0].Value = model.ShopId;
            parameters[1].Value = model.AccountMoney;
            parameters[2].Value = model.TotalPayMoney;
            parameters[3].Value = model.TotaChargeMoney;
            parameters[4].Value = model.PlatformTotalPayMoney;
            parameters[5].Value = model.ShopTotalPayMoney;
            parameters[6].Value = model.AddTime;
            parameters[7].Value = model.UpdateTime;
            parameters[8].Value = model.TotalCanSendCard;
            parameters[9].Value = model.AlreadySendCard;
            parameters[10].Value = model.IsDelete; var obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            return obj == null ? 0 : Convert.ToInt32(obj);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ShopSubsidiaryInfo model)
        {
            var strSql = new StringBuilder();
            strSql.Append("update ShopSubsidiaryInfo set ");

            strSql.Append(" ShopId = @ShopId , ");
            strSql.Append(" AccountMoney = @AccountMoney , ");
            strSql.Append(" TotalPayMoney = @TotalPayMoney , ");
            strSql.Append(" TotaChargeMoney = @TotaChargeMoney , ");
            strSql.Append(" PlatformTotalPayMoney = @PlatformTotalPayMoney , ");
            strSql.Append(" ShopTotalPayMoney = @ShopTotalPayMoney , ");
            strSql.Append(" AddTime = @AddTime , ");
            strSql.Append(" UpdateTime = @UpdateTime , ");
            strSql.Append(" TotalCanSendCard = @TotalCanSendCard , ");
            strSql.Append(" AlreadySendCard = @AlreadySendCard , ");
            strSql.Append(" IsDelete = @IsDelete  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@ShopId", SqlDbType.Int,4) ,            
                        new SqlParameter("@AccountMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@TotalPayMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@TotaChargeMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@PlatformTotalPayMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ShopTotalPayMoney", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@AddTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@TotalCanSendCard", SqlDbType.Int,4) ,            
                        new SqlParameter("@AlreadySendCard", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1)             
              
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.ShopId;
            parameters[2].Value = model.AccountMoney;
            parameters[3].Value = model.TotalPayMoney;
            parameters[4].Value = model.TotaChargeMoney;
            parameters[5].Value = model.PlatformTotalPayMoney;
            parameters[6].Value = model.ShopTotalPayMoney;
            parameters[7].Value = model.AddTime;
            parameters[8].Value = model.UpdateTime;
            parameters[9].Value = model.TotalCanSendCard;
            parameters[10].Value = model.AlreadySendCard;
            parameters[11].Value = model.IsDelete; return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            var strSql = new StringBuilder();
            strSql.Append("update ShopSubsidiaryInfo set IsDelete=1 ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            var strSql = new StringBuilder();
            strSql.Append("update ShopSubsidiaryInfo set IsDelete=1 ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            return DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataSet GetModel(int Id)
        {
            var strSql = new StringBuilder();
            strSql.Append("select Id, ShopId, AccountMoney, TotalPayMoney, TotaChargeMoney, PlatformTotalPayMoney, ShopTotalPayMoney, AddTime, UpdateTime, TotalCanSendCard, AlreadySendCard, IsDelete  ");
            strSql.Append("  from ShopSubsidiaryInfo ");
            strSql.Append(" where Id=@Id  and IsDelete=0");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            var ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows.Count > 0 ? ds : null;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM ShopSubsidiaryInfo where IsDelete=0 ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" and " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion
		
		#region 扩展方法
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataSet GetModelByShopId(int shopId)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * from ShopSubsidiaryInfo ");
            strSql.Append(" where ShopId=@ShopId and IsDelete=0");
            SqlParameter[] parameters = {
					new SqlParameter("@ShopId", SqlDbType.Int,4)
			};
            parameters[0].Value = shopId;
            var ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows.Count > 0 ? ds : null;
        }
		#endregion
	}
}
